package com.example.taximeter.mapper;

import com.example.taximeter.bean.Taximeter;
import com.example.taximeter.bean.TaximeterView;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * 计价器管理
 */
@Mapper
public interface TaximeterMapper {

    //查询计价器列表
    @SelectProvider(type = ActivityMapperProvider.class, method = "findTaximeterAll")
    @Results({
            @Result(property = "id", column = "id"),
            @Result(property = "factname", column = "fact_name"),
            @Result(property = "carno", column = "car_no"),
            @Result(property = "pricetype", column = "price_type"),
            @Result(property = "companyname", column = "company_name"),
            @Result(property = "jjqtype", column = "jjq_type"),
            @Result(property = "factid", column = "fact_id"),
            @Result(property = "priceid", column = "price_id"),
            @Result(property = "companyid", column = "company_id"),
            @Result(property = "jjqtypeid", column = "jjq_type_id")
    })
    List<TaximeterView> findTaximeterAll(TaximeterView taximeterView);

    //修改计价器信息
    @Update("update tab_base_jjq set fact_id = #{factid,jdbcType=INTEGER},price_id = #{priceid,jdbcType=INTEGER},jjq_type_id = #{jjqtypeid,jdbcType=INTEGER} where id = #{id,jdbcType=INTEGER}")
    boolean updateTaximeter(TaximeterView taximeterView);

    //删除计价器信息
    @Delete("delete from tab_base_jjq where id = #{id,jdbcType=INTEGER}")
    boolean deleteTaximeter(int id);

    //查询计价器列表(增加时)
    @SelectProvider(type = ActivityMapperProvider.class, method = "findTaximeterList")
    @Results({
            @Result(property = "id", column = "id"),
            @Result(property = "factname", column = "fact_name"),
            @Result(property = "carno", column = "car_no"),
            @Result(property = "pricetype", column = "price_type"),
            @Result(property = "companyname", column = "company_name"),
            @Result(property = "jjqtype", column = "jjq_type"),
            @Result(property = "factid", column = "fact_id"),
            @Result(property = "priceid", column = "price_id"),
            @Result(property = "companyid", column = "company_id"),
            @Result(property = "jjqtypeid", column = "jjq_type_id")
    })
    List<TaximeterView> findTaximeterList(TaximeterView taximeterView);

    //新增计价器信息
    @Insert("insert into tab_base_jjq (fact_id, price_id, company_id, \n" +
            "      jjq_type_id, car_no)\n" +
            "    values (#{factid,jdbcType=INTEGER}, #{priceid,jdbcType=INTEGER}, #{companyid,jdbcType=INTEGER}, \n" +
            "      #{jjqtypeid,jdbcType=INTEGER}, #{carno,jdbcType=VARCHAR})")
    Boolean addTaximeter(Taximeter taximeter1);

    //查询计价器信息(车牌号)
    @Select("select id  from tab_base_jjq where car_no = #{carno,jdbcType=VARCHAR} ")
    List<Taximeter> findTaximeterByCarno(@Param("carno") String carno);

    //查询计价器信息(出租车公司id)
    @Select("select id  from taximeter where company_id = #{companyid,jdbcType=INTEGER} ")
    List<Taximeter> findTaximeterByCompanyid(Integer companyid);

    //查询计价器信息(计价器厂商id)
    @Select("select id  from taximeter where fact_id = #{factid,jdbcType=INTEGER} ")
    List<Taximeter> findTaximeterByFactid(Integer factid);

    //查询计价器信息(价格类型id)
    @Select("select id  from taximeter where price_id = #{priceid,jdbcType=INTEGER} ")
    List<Taximeter> findTaximeterByPriceid(Integer priceid);

    //查询计价器信息(计价器型号id)
    @Select("select id  from taximeter where jjq_type_id = #{jjqtypeid,jdbcType=INTEGER} ")
    List<Taximeter> findTaximeterByJjqtypeid(Integer jjqtypeid);
}
